Skip to content

Wire cloud workflow and integration runtime defaults#136

Merged
khaliqgant merged 8 commits into
mainfrom
fix/cloud-runtime-workflow-integrations
May 23, 2026
Merged

Wire cloud workflow and integration runtime defaults#136
khaliqgant merged 8 commits into
mainfrom
fix/cloud-runtime-workflow-integrations

Conversation

@khaliqgant
Copy link
Copy Markdown
Member

@khaliqgant khaliqgant commented May 23, 2026

Summary

Implements the workforce runtime slice of AgentWorkforce/cloud#1028:

  • build a real cloud-backed ctx.workflow when WORKFORCE_WORKSPACE_TOKEN and WORKFORCE_CLOUD_BASE_URL are present
  • wire declared slack, linear, notion, and jira integrations through the existing runtime client factories
  • default Relayfile writeback receipt waits to 3000ms so provider IDs/Slack ts values are surfaced, with WORKFORCE_RELAYFILE_WRITEBACK_TIMEOUT_MS override

Workflow wire contract

ctx.workflow.run(name, args) resolves bundled source from workflows/.ts and POSTs to /api/v1/workflows/run with:

  • Authorization: Bearer <WORKFORCE_WORKSPACE_TOKEN>
  • x-agentworkforce-workspace-workflow-invocation: true
  • body: { workflow, fileType: "ts", sourceFileType: "workflow", runtime: { id: "daytona" }, metadata: { invocationSlug, invocationArgs } }

completion()/status() poll GET /api/v1/workflows/runs/{runId} with the same bearer token.

Tests

  • corepack pnpm --filter @agentworkforce/runtime test
  • corepack pnpm -r typecheck (fails in existing packages/cli/src/cli.ts MountHandle type mismatch outside this runtime slice)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 23, 2026

Warning

Review limit reached

@khaliqgant, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 1 review/hour. Refill in 14 minutes and 57 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fad79cbb-6bbc-4371-8eea-fb80fe751d23

📥 Commits

Reviewing files that changed from the base of the PR and between f83eb1c and e84cf6c.

📒 Files selected for processing (10)
  • packages/runtime/src/clients/github.test.ts
  • packages/runtime/src/clients/jira.test.ts
  • packages/runtime/src/clients/linear.test.ts
  • packages/runtime/src/clients/notion.test.ts
  • packages/runtime/src/clients/request.ts
  • packages/runtime/src/clients/slack.test.ts
  • packages/runtime/src/cloud-defaults.ts
  • packages/runtime/src/runner.test.ts
  • packages/runtime/src/runner.ts
  • packages/runtime/src/types.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cloud-runtime-workflow-integrations

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 10 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/runtime/src/cloud-defaults.ts">

<violation number="1" location="packages/runtime/src/cloud-defaults.ts:302">
P2: `runId` is validated as trimmed but encoded untrimmed, so whitespace-padded IDs can generate incorrect workflow status URLs.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/runtime/src/cloud-defaults.ts Outdated
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/runtime/src/cloud-defaults.ts
@khaliqgant
Copy link
Copy Markdown
Member Author

Shadow review (claude-2) — #1028 Fix 1/2/3 runtime

Reviewed at HEAD 81e8e3d (incl. 4712f1a, 069b4ab), cross-checked line-by-line against cloud origin/main for the contract surface. Note: CodeRabbit reported SUCCESS but was rate-limited and did not actually review this PR — so cubic + this pass are the only substantive review here.

Fix 1 — ctx.workflow (cloud-defaults.ts): runtime side correct ✅

The POST/poll wiring, status mapping, and result extraction match cloud's actual contract (verified against workflows/callback/route.ts:47-48 + workflows/runs/[runId]/route.ts):

  • Status enum maps cloud's real values: completed→success, failed/cancelled→failure; pending/running non-terminal; unknown→keep-polling. (Originally the runtime only recognized success/failure, so completion() would have spun to the timeout on every real run and never returned — fixed in 81e8e3d.)
  • Reads body.result (cloud stores the result under result, not output) and surfaces patches, so the PR URL at patches[].pushedTo.prUrl is reachable from completion().output.
  • completion() timeout = 90m, covering the bundled 75m small-issue workflow.
  • Robustness: 15s per-request AbortController timeout; up to 3 consecutive transient retries (network/timeout/429/5xx) with fail-loud on 401/403 so token expiry isn't masked.

⚠️ Cross-repo dependency (gates E2E, not this PR's code). Fix 1 only works once the cloud side lands (tracked with the cloud PR):

  1. workflows/run/route.ts:581-588 currently gates the workspace path on a per-process crypto.randomUUID() header (route.ts:98) that a sandbox can't reproduce → 403. Cloud is switching to accept a verified workflow:invoke:write token without the random-header coupling.
  2. The minted workspace token needs both workflow:invoke:write (POST) and workflow:runs:read (the GET poll route, runs/[runId]/route.ts:16) — workflow:invoke:read does not satisfy the poll route. Cloud is updating the token scopes + bumping TTL to 2h.

Runtime now sends the correct header name x-agentworkforce-workspace-workflow-invocation (4712f1a).

Fix 2 — slack/linear/notion/jira wiring: correct ✅ — two minor notes

  • slack and jira are gated on WORKFORCE_WORKSPACE_TOKEN being present; if it's absent they're silently not wired (no ctx.slack, no diagnostic). Consider a debug log so a missing token is diagnosable rather than surfacing as a bare "ctx.slack is undefined".
  • The github client's cloudApiToken precedence flipped to prefer WORKFORCE_WORKSPACE_TOKEN over WORKFORCE_AGENT_TOKEN (was the reverse). Intended? It changes which token authenticates github writebacks when both are set.

Fix 3 — writeback timeout (request.ts): correct ✅

Default 3000ms (DEFAULT_WRITEBACK_TIMEOUT_MS), 0→fire-and-forget, bounded poll loop (deadline = now + timeoutMs) — no unbounded hang. Env override WORKFORCE_RELAYFILE_WRITEBACK_TIMEOUT_MS is plumbed, and ="0" correctly re-disables (numberFromEnv preserves 0). The default now flips every integration write from instant to up-to-3s-blocking — bounded + intended (it's how post()/comment() return the real ts).

Verdict

Runtime side LGTM, pending the cloud PR landing the auth/scope/TTL changes above (I'm reviewing that separately). The pre-existing packages/cli/src/cli.ts(1984,70) MountHandle typecheck failure is unrelated to this PR (documented in #135) and not attributable here.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/runtime/src/cloud-defaults.ts Outdated
@khaliqgant khaliqgant merged commit 5d22bf2 into main May 23, 2026
3 checks passed
@khaliqgant khaliqgant deleted the fix/cloud-runtime-workflow-integrations branch May 23, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant